package com.binc.testspring.service.impl;

import com.binc.testspring.service.ICustomerService;
import com.binc.testspring.service.RetrofitApi2;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;

/**
 * 这是正常项目中的service接口层；
 */
@Slf4j
@Service
public class CustomerServiceImpl implements ICustomerService {

    /**
     * 这里直接使用retrofit接口
     */
    @Autowired
    RetrofitApi2 retrofitApi2 ;
    
    @Override
    public JsonObject retrofitClientTest() throws IOException {
        Call<JsonObject> jsonObjectCall = retrofitApi2.binc4();
        Response<JsonObject> execute = jsonObjectCall.execute();
        if (execute.isSuccessful()) {
            return execute.body();
        }

        return null;
    }

    @Override
    public String helloWorld() {
        return "binc";
    }
}
